function [N1 N2 P1 P2 N1Val N2Val P1Val P2Val] = RetrievePeakInfo(peaksDB, subject, electrode)
% If no electrode is given, only grand average will be returned.

%TODO Check if subject exists..
%     if isempty(N1) || isempty(N2) || isempty(P1) || isempty(P2)
%         error('GrandAv unknown');
%     end

if isempty(peaksDB)
    d = load('PeaksDBLV');
    peaksDB = d.peaksDBLV;
end

N1rowNr = strcmp(subject.PeakDataDescription, peaksDB.N1(:,1));
N2rowNr = strcmp(subject.PeakDataDescription, peaksDB.N2(:,1));
P1rowNr = strcmp(subject.PeakDataDescription, peaksDB.P1(:,1));
P2rowNr = strcmp(subject.PeakDataDescription, peaksDB.P2(:,1));

if exist('electrode', 'var')
    disp(['Retrieving peak info for subject ' subject.Name ', electrode ' electrode]);
    
    N1colNr = strcmp([electrode '-Peaks-L'], peaksDB.N1(1,:));
    N1 = cell2mat(peaksDB.N1(N1rowNr,N1colNr));

    N2colNr = strcmp([electrode '-Peaks-L'], peaksDB.N2(1,:));
    N2 = cell2mat(peaksDB.N2(N2rowNr,N2colNr));

    P1colNr = strcmp([electrode '-Peaks-L'], peaksDB.P1(1,:));
    P1 = cell2mat(peaksDB.P1(P1rowNr,P1colNr));

    P2colNr = strcmp([electrode '-Peaks-L'], peaksDB.P2(1,:));
    P2 = cell2mat(peaksDB.P2(P2rowNr,P2colNr));
    
    N1colNr = strcmp([electrode '-Peaks-V'], peaksDB.N1(1,:));
    N1Val = cell2mat(peaksDB.N1(N1rowNr,N1colNr));
    
    N2colNr = strcmp([electrode '-Peaks-V'], peaksDB.N2(1,:));
    N2Val = cell2mat(peaksDB.N2(N2rowNr,N2colNr));
    
    P1colNr = strcmp([electrode '-Peaks-V'], peaksDB.P1(1,:));
    P1Val = cell2mat(peaksDB.P1(P1rowNr,P1colNr));
    
    P2colNr = strcmp([electrode '-Peaks-V'], peaksDB.P2(1,:));
    P2Val = cell2mat(peaksDB.P2(P2rowNr,P2colNr));
    
else
    disp(['Retrieving peak info for subject ' subject.Name]);

    
error    %TODO Gemiddelde latency ofzo..
    N1 = cell2mat(peaksDB.N1(N1rowNr,2));
    N2 = cell2mat(peaksDB.N2(N2rowNr,2));
    P1 = cell2mat(peaksDB.P1(P1rowNr,2));
    P2 = cell2mat(peaksDB.P2(P2rowNr,2));

    if isempty(N1) || isempty(N2) || isempty(P1) || isempty(P2)
        error('GrandAv unknown');
    end

end